<template>
  <div>
    <router-link tag="div"
                 to="/"
                 class="header_abs"
                 v-show="showAbc"
    >
      <span class="iconfont back_icon">&#xe624;</span>
    </router-link>
    <div class="header-fixed"  v-show="!showAbc" :style="opacityStyle">
      景点详情
      <router-link to="/">
        <span class="iconfont header_fixed_back">&#xe624;</span>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbc: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {/*因为opacityStyle是一个对象 所以下面的this.opacityStyle也要{}；opacity = opacity > 1 ? 1 : opacity中的 opacity是上句的opaity*/
    /*  console.log(scroll)*/
      const top = document.documentElement.scrollTop
      if (top > 50) {
        let opacity = top / 130
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {opacity}
        this.showAbc = false
      } else {
        this.showAbc = true
      }
      console.log(document.documentElement.scrollTop)
    }

  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header_abs
    position: absolute
    z-index: 9
    left: .2rem
    top: .2rem
    width: .8rem
    height: .8rem
    border-radius: 50%
    line-height: .8rem
    background: rgba(0, 0, 0, .7)
    text-align: center
    .back_icon
      color: #fff
      font-size: .4rem
  .header-fixed
    position fixed
    z-index: 9
    top: 0
    left: 0
    right: 0
    height: $headerHeight
    line-height: $headerHeight
    text-align: center
    color: #fff
    background: $bjColor
    font-size: .32rem;
    .header_fixed_back
      position: absolute
      left: 0
      width: .64rem
      font-size: .4rem
      color: white
</style>
